package leetcode;

import java.util.*;

/**
 * Created by Ghost on 2015/1/18 0018.
 */
public class Largest_Number {
    LinkedList<List<Integer>> numLst = new LinkedList<List<Integer>>();
    public void getTotalSort(int[] nums,int start){
        if(start==nums.length){
            List<Integer> lst = new LinkedList<Integer>();
            for(int i=0;i<nums.length;i++){
                lst.add(nums[i]);
            }
            numLst.add(lst);
        }
        else{
            for(int i=start;i<nums[i];i++){
                if(i>start && nums[i]==nums[start])
                    continue;
                int tmp = nums[i];
                nums[i] = nums[start];
                nums[start] = tmp;
                getTotalSort(nums,start+1);
                nums[start] = nums[i];
                nums[i] = tmp;
            }
        }
    }

    public String largestNumber(int[] num) {
        if(num==null || num.length==0)
            return "";

        String[] nums = new String[num.length];
        for(int i=0;i<num.length;i++){
            nums[i] = ""+num[i];
        }

        Arrays.sort(nums,new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return (o2+o1).compareTo(o1+o2);
            }
        });
       String RST="";
        for(int i=0;i<nums.length;i++){
            RST+=nums[i];
        }
        if(RST.charAt(0)=='0')
            RST="0";

        return RST;
    }
    public static void main(String[] args){
        Largest_Number largest_number = new Largest_Number();
        int[] num = {3, 30, 34, 5, 9};
        String rst = largest_number.largestNumber(num);
        System.out.println(rst);
    }
}
